<?php
/*
 *网站前台的公共文件：对应的操作有友好404提示，获取网站配置，获取文章列表 图片列表 获取指定 ID 
 *
 */
class site_common extends spController
{
	//public $domain;
	function __construct(){
		parent::__construct();
		$this->bottominfo=array(
			'copyright'=>$this->siteConfig(11),
			'tel'=>$this->siteConfig(23),
			'icp'=>$this->siteConfig(24),
			'statistics'=>$this->siteConfig(8),									
		);
		$this->floatText=$this->siteConfig(25);
		}
	public function error404(){
		header('HTTP/1.1 404 404 Not Found');
		echo'<div style="width:100%; text-align:center; margin-top:66px;"><img src="./images/404.png"/></div>';
		die;
	}
	public function siteConfig($id,$conditions=null){
		$sc=spClass('site_config');
		if(is_null($conditions)){
			$res=$sc->spCache(864000)->find('id='.$id,$sort = null, $fields='value');
			return $res[value];	
		}else{
			$res=$sc->spCache(864000)->findAll($conditions,$sort = null, $fields='id,value');
			$temp=array();
			foreach($res as $v){
				$temp[$v['id']]	=$v['value'];
			}
			return $temp;		
		}	
	}	
	public function seo($umeta_id=0){
		$seo=array(
			'name'=>$this->siteConfig(1),
			'title'=>$this->siteConfig(2),
			'info'=>$this->siteConfig(3),
		);
		if($umeta_id!=0){
			$seo_meta=spClass('site_meta');
			$seo_meta=$seo_meta->find($conditions=array('umeta_id'=>$umeta_id));
			$seo=array_merge($seo,array('keywords'=>$seo_meta['meta_key'],'description'=>$seo_meta['meta_des']));		
		}
		$this->seo=$seo;		
	}
	public function getList($fid,$limit=null,$page=1,$pagesize=10,$private=true){
		$post=spClass('posts');
		if(!empty($limit)){
			$res=$post->findAll($conditions = array('fid'=>$fid,'post_satus'=>'1',),$sort='sid desc',$fields='id,post_title,post_summary,post_date',$limit);
		}else{
			$res=$post->spPager($page,$pagesize)->findAll($conditions = array('fid'=>$fid,'post_satus'=>'1',),$sort='sid desc',$fields='id,post_title,post_summary,post_date'); 
			$this->pager = $post->spPager()->getPager();
			unset($post);		
		}
		return $res;		
		}
	public function imgPlayer($conditions ,$limit=null){
		$ip=spClass(img_player);
		$res=$ip->spCache(864000)->findAll($conditions,$sort='show_order desc',$fields=null,$limit); 
		unset($ip);
		return $res;		
	}		
	public function getArticle($id,$private=true,$fid=null){
		$id=intval($id);
		$post=spClass('posts');
		$conditions='id='.$id;
		$res=$post->spCache(864000)->find($conditions,$sort = null,$fields ='id,fid,post_title,post_datil,umeta_id,post_satus,post_date,post_summary');
		if($private!=true){
			$fid=$res['fid'];
		}
		if($res[post_satus]==1&&($res['fid']==$fid||in_array($res['fid'],$fid))){
			$this->seo($res['umeta_id']);
			return $res;
		}else{
			$this->error404();//if set the page not to dispaly return  404 status
		}
	}				
}